package com.zhonghe.active4j;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.junit.Test;

import com.aliyun.oss.common.utils.StringUtils;

public class MyTest {

	//@Test
	public void test0() {
		String formula = "xa+xb+xc*(xd-xe)-xf/xg";
		String spiltRules = "\\+|-|\\*|/|=|\\(|\\)|;";
		String[] array = formula.split(spiltRules);
		for (String s : array) {
			System.out.println(s);
		}

		System.out.println("=====分割线=====");
		// 第二种方式,利用正则匹配
		List<String> listCompile = new ArrayList<>();
		Matcher matcher = Pattern.compile("\\bx\\w{1}").matcher(formula);// 用正则匹配
		while (matcher.find()) {
			listCompile.add(matcher.group(0));
			System.out.println(matcher.group(0));
		}
		System.out.println(listCompile);
	}
	
	//@Test
	public void test9() {
		String formula = "T{person:[sum(amount)]:[id=9;code=9]}";
		// 第二种方式,利用正则匹配
		List<String> listCompile = new ArrayList<>();
		Matcher matcher = Pattern.compile("^T{[\\s\\S]*:\\[[\\s\\S]*\\]:\\[[\\s\\S]*\\]}$").matcher(formula);
		System.out.println(matcher.matches());
		
		
		matcher = Pattern.compile("\\b[T]|\\(\\)\\w{1}|\\b[Sa]|\\(\\)\\w{1}").matcher(formula);// 用正则匹配
		while (matcher.find()) {
			listCompile.add(matcher.group(0));
			System.out.println(matcher.group(0));
		}
		System.out.println(listCompile);
	}
	
	public static void main(String args[]) {
		String str = "T{person:[sum(amount)]:[id=9;code=9]}";
		String pattern = "^T\\{[\\s\\S]*:\\[[\\s\\S]*\\]:\\[[\\s\\S]*\\]\\}$";

		List<String> listCompile = new ArrayList<>();
		Pattern r = Pattern.compile(pattern);
		Matcher m = r.matcher(str);
		//System.out.println(m.matches());
		while (m.find()) {
			listCompile.add(m.group(0));
			System.out.println(m.group(0));
		}
		System.out.println(listCompile);
	}
	
	@Test
	public void test99() {
		String str = "asdasdadasd";
		System.out.println(15&(str.hashCode()^(str.hashCode()>>>16)));
	}
}
